package top.ruanlitao.shortlink.project.mq.redis.producer;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import top.ruanlitao.shortlink.project.common.constant.RedisKeyConstant;
import top.ruanlitao.shortlink.project.mq.producer.ShortLinkStatsSaveProducer;

import java.util.Map;

/**
 * 短链接监控状态保存消息队列生产者
 */
@ConditionalOnProperty(prefix = "short-link.message-queue", name = "type", havingValue = "redis")
@Component("redisShortLinkStatsSaveProducer")
@RequiredArgsConstructor
@Slf4j
public class RedisShortLinkStatsSaveProducer implements ShortLinkStatsSaveProducer {

    private final StringRedisTemplate stringRedisTemplate;

    /**
     * 发送保存统计信息的消息
     */
    @Override
    public void send(Map<String, String> producerMap) {
        stringRedisTemplate.opsForStream().add(RedisKeyConstant.STATS_STREAM_TOPIC_KEY, producerMap);
        log.info("生产者生产数据至【Redis】消息队列");
    }
}
